home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / CIRCTXT.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  3KB  |  162 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #ifdef SGI
  5. #include "gl.h"
  6. #include "device.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #ifndef TC
  13. #include <math.h>
  14. #else
  15. extern double    sin(), cos();
  16. #endif
  17.  
  18. #define pi 3.1415926535
  19.  
  20. char *fonts[] = {
  21.     "astrology",
  22.     "cursive",
  23.     "futura.l",
  24.     "futura.m",
  25.     "gothic.eng",
  26.     "gothic.ger",
  27.     "gothic.ita",
  28.     "greek",
  29.     "japanese",
  30.     "markers",
  31.     "math.low",
  32.     "math.upp",
  33.     "meteorology",
  34.     "music",
  35.     "cyrillic",
  36.     "script",
  37.     "symbolic",
  38.     "times.g",
  39.     "times.ib",
  40.     "times.i",
  41.     "times.r",
  42.     "times.rb"
  43. };
  44.  
  45. void ShowCircularText();
  46.  
  47. /*
  48.  * display all the hershey fonts and demonstrate textang
  49.  */
  50. main()
  51. {
  52.     char    buf[50];
  53.     char    *str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  54.     char    *str2 = "abcdefghijklmnopqrstuvwxyz" ;
  55.     char    *str3 = "1234567890+-=!@#$%^&*(){}[]" ;
  56.     char    *str4 = "<>,./?~`\\|_BONK,blark" ;
  57.     int    i;
  58.     short    val;
  59.  
  60.     winopen("circtxt");
  61.  
  62.     hleftjustify(1);
  63. #ifdef THINK_C
  64. #else
  65.     hsetpath("/tmp");
  66. #endif
  67.  
  68.     unqdevice(INPUTCHANGE);
  69.     qdevice(KEYBD);
  70.  
  71.     color(BLACK);
  72.     clear();
  73.  
  74.     ortho2(-14.0, 14.0, -14.0, 14.0);    /* define the world space */
  75.  
  76.     for(i = 0; i < 22; i++) {
  77.  
  78.         /*
  79.          * textang is used to specify the orientation of text. As
  80.          * we want the title to come out straight we make sure it is
  81.          * zero each time we go through this loop.
  82.          */
  83.         htextang(0.0);
  84.  
  85.         /*
  86.          * do the title
  87.          */
  88.         color(YELLOW);
  89.         hfont("futura.m");
  90.         sprintf(buf, "This is hershey font %s", fonts[i]);
  91.         hboxtext(-11.0, 12.0, 20.0, 1.0, buf);
  92.  
  93.         /*
  94.          * draw a box around the title
  95.          */
  96.         rect(-11.0, 12.0, 9.0, 13.0);
  97.  
  98.         color(GREEN);
  99.  
  100.         hfont(fonts[i]);        /* grab a font from the table */
  101.  
  102.         htextsize(1.5, 1.5);        /* show the outer ring */
  103.         ShowCircularText(11.0, str1);
  104.  
  105.         htextsize(1.3, 1.3);        /* show the second ring */
  106.         ShowCircularText(8.5, str2);
  107.  
  108.         htextsize(1.1, 1.1);        /* show the third ring */
  109.         ShowCircularText(7.0, str3);
  110.  
  111.         htextsize(0.9, 0.9);        /* show the inside ring */
  112.         ShowCircularText(5.0, str4);
  113.  
  114.         if (qread(&val) == QKEY) {
  115.             gexit();
  116.             exit(0);
  117.         }
  118.  
  119.         color(BLACK);
  120.         clear();
  121.     }
  122.  
  123.     gexit();
  124. }
  125.  
  126. /*
  127.  * ShowCircularText
  128.  *
  129.  *    show a ring of text
  130.  */
  131. void
  132. ShowCircularText(r, str)
  133.     double    r;
  134.     char    *str;
  135. {
  136.     double    i, inc, x, y;
  137.     double    a;
  138.  
  139.     inc = 360.0 / (double)strlen(str);
  140.  
  141.     for (i = 0; i < 360.0; i += inc) {
  142.         /*
  143.          * calculate the next drawing position
  144.          */
  145.         x = r * cos(i * pi / 180.0);
  146.         y = r * sin(i * pi / 180.0);
  147.         move2(x, y);
  148.         /*
  149.          * calculate angle for next character
  150.          */
  151.         a = (90 + i);
  152.         /*
  153.          * set the orientation of the next character
  154.          */
  155.         htextang(a);
  156.         /*
  157.          * draw the character
  158.          */
  159.         hdrawchar(*str++);
  160.     }
  161. }
  162.